package cn.wyh.security.security;

import cn.wyh.utils.MD5;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;


/**
 * @author wyh
 * @version 1.0
 * @date 2021/10/4 16:51
 */
@Component
public class DefaultPasswordEncoder implements PasswordEncoder {


    public DefaultPasswordEncoder() {
        this(-1);
    }

    public DefaultPasswordEncoder(int Strength) {
    }

    /**
     * md5加密
     * @param rawPassword 密码
     * @return 加密后
     */
    @Override
    public String encode(CharSequence rawPassword) {
        return MD5.encrypt(rawPassword.toString());
    }

    /**
     * 进行密码比对
     * @param rawPassword 密码
     * @param encodedPassword 加密后密码
     * @return 结果
     */
    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        return encodedPassword.equals(MD5.encrypt(rawPassword.toString()));
    }
}
